﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverTile.Xaml;
using SilverTile.Sprites;

namespace SilverTile.ExtensionMethods
{
    public static class ResourceDictionaryExtensionMethods
    {

        public static T GetSprite<T>(this ResourceDictionary dictionary, string key) where T: AnimatedSprite
        {

            if (!dictionary.Contains(key))
            {
                throw new ArgumentOutOfRangeException("No resource with key " + key + " was found");
            }

            var spriteAnimation = dictionary[key] as SpriteAnimation;
            if (spriteAnimation == null)
            {
                throw new ArgumentException("Resource with key " + key + " is not a SpriteAnimation");
            }

            return spriteAnimation.GetAnimatedSprite<T>();

        }

    }
}
